# 和url中的参数一样，cookie也可以单独传入
import requests
from fake_useragent import FakeUserAgent

# 定义网址
url = 'https://www.baidu.com/my/index'

# 定义请求头，包含用户代理
headers = {'User-Agent': FakeUserAgent().random}

# 单独定义cookie信息
cookie = {
    "BIDUPSID": "560CAE0963372802B9293DEE7EAC5ECD",
    "PSTM": "1718077633",
    "BAIDUID": "3E60D8AE5F7B217324B746099AB5D664:FG=1",
    "BD_UPN": "12314753",
    "BDUSS": "m4wN3AwazdxSXR1cWg5cmRVYVVma0VjRlBnazZxTEhuMW9tVmpUQWE1dmc1aGxvSVFBQUFBJCQAAAAAAQAAAAEAAADrhWloAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOBZ8mfgWfJnW",
    "BDUSS_BFESS": "m4wN3AwazdxSXR1cWg5cmRVYVVma0VjRlBnazZxTEhuMW9tVmpUQWE1dmc1aGxvSVFBQUFBJCQAAAAAAQAAAAEAAADrhWloAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOBZ8mfgWfJnW",
    "H_WISE_SIDS": "61027_61672_62325_62338_62831_62844_62865_62878_62880_62884_62926_62917_62967",
    "BAIDUID_BFESS": "3E60D8AE5F7B217324B746099AB5D664:FG=1",
    "ZFY": "c55CUMgstlk:Ak4vUs5FyInocLB711AAdWlsP5MxrJys:C",
    "COOKIE_SESSION": "2373603_5_4_5_8_5_1_0_3_4_42_0_2373646_4322904_47_5_1744806090_1744806048_1744806043%7C9%234322904_33_1744806043%7C9",
    "H_PS_PSSID": "61027_61672_62325_62338_62831_62865_62878_62880_62884_62926_62967",
    "__bid_n": "1935dc44ab80288d3bc325",
    "RT": "\"z=1&dm=baidu.com&si=7bf0499f-dc2f-4ee7-b4ea-ac8c8f8bb62f&ss=m9sm2nhh&sl=b&tt=3qj&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=522k&ul=5pym&hd=5pyq\"",
    "H_WISE_SIDS_BFESS": "61027_61672_62325_62338_62831_62844_62865_62878_62880_62884_62926_62917_62967",
    "BDORZ": "FAE1F8CFA4E8841CC28A015FEAEE495D"
}

# 发起网络请求并保存
response = requests.get(url, headers=headers, cookies=cookie)
with open('index.html', 'wb') as f:
    f.write(response.content)